import { defineStore } from 'pinia'
import { UserInfo } from '@/types/user'

const userStore = defineStore({
  id: 'userStore',
  state: () => {
    return {
      user: {
        id: '',
        avatar: '',
        nickname: '',
        account: '',
        mobile: '',
        token: ''
      } as UserInfo
    }
  },
  actions: {
    setUserInfo(data: UserInfo) {
      this.user = { ...data }
      localStorage.setItem('user', JSON.stringify({ user: this.user }))
      console.log(this.user, 'sdsdsdd')
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'user',
        storage: localStorage,
        paths: ['user']
      }
    ]
  }
})

export default userStore
